package com.gitee.wsl.ext.collection


/**
 * Returns a list of pairs, where each value corresponds to all possible pairings with values from [other].
 * this: A, B, C
 * other: 1, 2
 * this.cartesianProduct(other) = [A to 1, A to 2, B to 1, B to 2, C to 1, C to 2]
 */
fun <T, R> Iterable<T>.cartesianProduct(other: Iterable<R>): List<Pair<T, R>> =
    flatMap { value -> List(other.count()) { value }.zip(other) }